import com.example.demo3.Person;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;

public class JSONutils {
    private static ObjectMapper objectMapper = new ObjectMapper();
    public static void main(String[] args) throws JsonProcessingException {
        Person person = new Person();
        person.setName("酷酷的森");
        person.setAge(18);
        //java对象转json字符串
        String json=objectMapper.writeValueAsString(person);
        System.out.println("json字符串为："+json);
        //json字符串转java对象
        Person p=objectMapper.readValue(json, Person.class);
        System.out.println("name"+p.getName()+",age"+p.getAge());
    }
}
